

/******************** 定义类 ***************************************************************/
/*
    步骤类
 */

function Step() {
    Object.assign(this, {
        id: 0,
        title: "",
        content: "",
        allow_demand_upload: true,
        allow_checking_modify: false,
        remark: "",
        appendix: [],
        service_remark: "", 
        service_appendix: [],
        demand_remark: "", 
        demand_appendix: [],
        status: 0,
        failed_reason: "",
        is_modifing: false
    });
}

// 将对象序列化为一个json对象，可以用于http请求或对象复制
Step.prototype.serialize = function() {
    return Object.assign({}, this, {
        appendix_ids: this.appendix.map(function(elem){return elem.id}).join(","),
        service_appendix_ids: this.service_appendix.map(function(elem){return elem.id}).join(","),
        demand_appendix_ids: this.demand_appendix.map(function(elem){return elem.id}).join(",")
    });
}

// 用json数据为对象属性赋值
Step.prototype.parse = function(data) {
    Object.assign(this, data||{});
    if(data.allow_checking_modify != undefined) this.allow_checking_modify = data.allow_checking_modify == 1;
    if(data.allow_demand_upload != undefined) this.allow_demand_upload = data.allow_demand_upload == 1;
}

// ******************** 类静态属性与方法 **********************************************
// 解析json数据，返回一个对象
Step.parse = function(data) {
    var o = new Step();
    o.parse(data);
    return o;
}

// 解析json数组，返回对象数组
Step.parseList = function(list) {
    var len = list.length;
    var arr = new Array(len);
    for(var i = 0; i < len; i++) {
        arr[i] = Step.parse(list[i]);
    }
    return arr;
}

// ******************** 导出 **********************************************
export default Step